import axios from 'axios'
import { fromJS } from 'immutable'

export const SEARCH_FOCUS = 'SEARCH_FOCUS'
export const ADD_HEADER_LIST = 'ADD_HEADER_LIST'
export const SEARCH_BLUR = 'SEARCH_BLUR'
export const MOUSE_ENTER = 'MOUSE_ENTER'
export const MOUSE_LEAVE = 'MOUSE_LEAVE'
export const PAGE_CHANGE = 'PAGE_CHANGE'

export const getSearchFocusAction = () => ({
  type: SEARCH_FOCUS
})

export const getSearchBlurAction = () => ({
  type: SEARCH_BLUR
})

export const getMouseEnterAction = () => ({
  type: MOUSE_ENTER
})

export const getMouseLeaveAction = () => ({
  type: MOUSE_LEAVE
})

export const getSwitchClickAction = (page) => ({
  type: PAGE_CHANGE,
  page
})

export const getList = () => {
  return (dispatch) => {
     axios.get('/api/headerList.json').then((res) =>{
      const data = fromJS(res.data.data)
      dispatch({
        type: ADD_HEADER_LIST,
        list: data,
        totalPage: Math.ceil(res.data.data.length / 10)
      })
    }).catch(()=>{
      console.log('error')
    })
  }
}
